home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 10608 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.7 KB

  1. Path: hickory.westol.com!news
  2. From: Mark Kintigh <breetai@oak.westol.com>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Converting Strings to Upper Case
  5. Date: Mon, 18 Mar 1996 08:17:20 -0800
  6. Organization: Westmoreland Online Inc.
  7. Message-ID: <314D8C90.55C6@oak.westol.com>
  8. References: <4ifra6$52i@scipio.cyberstore.ca> <4ih7l3$526@thrush.sover.net>
  9. NNTP-Posting-Host: pm126.westol.com
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 2.0 (Win16; I)
  14.  
  15. Steve Mount wrote:
  16. > In article <4ifra6$52i@scipio.cyberstore.ca>, ejw@news.cyberstore.ca says...
  17. > >I need to write a function to convert a string containg upper or lower case
  18. > >characters to the opposite case.  Something like::
  19. > void strnlwr(char *buffer, int len)
  20. > {
  21. > register int i;
  22. > for (i=0;i<len;i++) buffer[i] = tolower(buffer[i]);
  23. > return;
  24. > }
  25. > Note I added a length checker, as this was required; it may not be the most
  26. > efficient, but it gets the job done.  It also prevents me from duplicating
  27. > the code that tolower/toupper does.
  28.  
  29. You don't need the length.  You could just use....
  30.  
  31. void str2upper(char *str)
  32. {
  33.   while(*str!='\0')
  34.   {
  35.     *str = toupper(*str);
  36.     str++;
  37.   }
  38. }
  39.  
  40. Of course, this assumes that you have properly terminated the string. :)
  41. -- 
  42.      _____
  43.     /    /##                 breetai@oak.westol.com
  44.    /    /####                                                     ____
  45.   (| []/ o ##)    "We met the enemy, and they were'nt us, then   | _|||
  46. |\ \_/ /\   # /|  we faced a pannel of 'us' and found they were  ||  ||
  47. | \-\ ==== /-/ |                    the enemy."                   \\//
  48. ||\\ '----' //||                                                   \/
  49. || \\/    \// ||
  50.